package com.kookapi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.kookapi.common.annotation.Log;
import com.kookapi.common.core.controller.BaseController;
import com.kookapi.common.core.domain.AjaxResult;
import com.kookapi.common.enums.BusinessType;
import com.kookapi.business.domain.TestTask;
import com.kookapi.business.service.ITestTaskService;
import com.kookapi.common.utils.poi.ExcelUtil;
import com.kookapi.common.core.page.TableDataInfo;

/**
 * 测试任务Controller
 * 
 * @author cleftgou
 * @date 2025-10-08
 */
@RestController
@RequestMapping("/business/task")
public class TestTaskController extends BaseController
{
    @Autowired
    private ITestTaskService testTaskService;

    /**
     * 查询测试任务列表
     */
    @PreAuthorize("@ss.hasPermi('business:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(TestTask testTask)
    {
        startPage();
        List<TestTask> list = testTaskService.selectTestTaskList(testTask);
        return getDataTable(list);
    }

    /**
     * 导出测试任务列表
     */
    @PreAuthorize("@ss.hasPermi('business:task:export')")
    @Log(title = "测试任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TestTask testTask)
    {
        List<TestTask> list = testTaskService.selectTestTaskList(testTask);
        ExcelUtil<TestTask> util = new ExcelUtil<TestTask>(TestTask.class);
        util.exportExcel(response, list, "测试任务数据");
    }

    /**
     * 获取测试任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:task:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(testTaskService.selectTestTaskById(id));
    }

    /**
     * 新增测试任务
     */
    @PreAuthorize("@ss.hasPermi('business:task:add')")
    @Log(title = "测试任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TestTask testTask)
    {
        return toAjax(testTaskService.insertTestTask(testTask));
    }

    /**
     * 修改测试任务
     */
    @PreAuthorize("@ss.hasPermi('business:task:edit')")
    @Log(title = "测试任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TestTask testTask)
    {
        return toAjax(testTaskService.updateTestTask(testTask));
    }

    /**
     * 删除测试任务
     */
    @PreAuthorize("@ss.hasPermi('business:task:remove')")
    @Log(title = "测试任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(testTaskService.deleteTestTaskByIds(ids));
    }
}
